package com.lhd.mpaas.demo.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;

import com.lhd.mpaas.demo.base.BaseActivity;

/**
 * 欢迎界面
 */
public class SplashActivity extends BaseActivity {

    /**
     * 是否是第一次运行
     */
    private boolean isFirst;
    private SharedPreferences preferences;
    private Editor editor;
    /**
     * 历史版本号
     */
    private int versionCode;

    private Handler handler = new Handler();
    /**
     * 当前安装版本号
     */
    private int currentVersionCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
        }
        preferences = getSharedPreferences("isFirst", MODE_PRIVATE);
        editor = preferences.edit();
        isFirst = preferences.getBoolean("isFirst", true);
        versionCode = preferences.getInt("versionCode", 1);
//        currentVersionCode = PackageUtils.getVersionCode(this, getPackageName());
        // 第一次安装或新版本显示引导页
        /*if (isFirst || currentVersionCode > versionCode) {
            // 将标志位设为true
            editor.putBoolean("isFirst", false).commit();
            editor.putInt("versionCode", currentVersionCode).commit();
            Intent intent = new Intent(this, GuideActivity.class);
            startActivity(intent);
            finish();
        } else {*/// 非首次运行且用户未注销 3秒后自动跳转
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
//                    overridePendingTransition(R.anim.aty_enter, R.anim.aty_exit);
            }
        }, 1000);
//        }
    }

    @Override
    protected int getLayoutId() {
        return 0;
    }
}
